package com.zhan.ielts.web.controller;

import com.zhan.frame.core.dao.BaseService;
import com.zhan.frame.core.web.controller.BaseControllerImpl;
import com.zhan.frame.core.web.domain.Result;
import com.zhan.frame.core.web.domain.Result.Status;
import com.zhan.ielts.domain.Message;
import com.zhan.ielts.service.MessageService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/message")
public class MessageController extends BaseControllerImpl<Message, Message> {

	private Logger log = LoggerFactory.getLogger(MessageController.class);

	@Autowired
	private MessageService messageService;
	@Override
	protected BaseService<Message> getBaseService() {
		return messageService;
	}

	@Override
	@RequestMapping(method = RequestMethod.POST)
	public ModelAndView addOne(Message entity) {
		entity.setPublishTime(new Date().getTime());
		getBaseService().insert(entity);
		return new ModelAndView(path.getRedirectListPath());
	}
	@Override
	@RequestMapping(method = RequestMethod.PUT)
	public ModelAndView editOne(Message entity) {
		entity.setPublishTime(new Date().getTime());
		getBaseService().updateById(entity);
		return new ModelAndView(path.getRedirectListPath());
	}
}
